<template name="newAdminUserTableRow">
{{#let txt="admin.userAccounts.newAdminUserTableRow"}}
{{!-- Expects:
   user: Object representing user with credentials
--}}
  <div class="account-row" role="row">
    <div class="account-role" role="gridcell">
      {{#if user.account.isAdmin}}
        <span class="user-class-admin" title="{{_ (con txt "admin.hint")}}">{{_ (con txt "admin.cap")}}</span>
      {{else}}
        {{#if isSignedUpOrDemo user.account}}
          <span class="user-class-user" title="{{_ (con txt "user.hint")}}">{{_ (con txt "user.cap")}}</span>
        {{else}}
          <span class="user-class-visitor" title="{{_ (con txt "visitor.hint")}}">{{_ (con txt "visitor.cap")}}</span>
        {{/if}}
      {{/if}}
    </div>
    <div class="profile-name" role="gridcell">{{ user.account.profile.name }}</div>
    <div class="credentials" role="gridcell">
      <ul class="credential-list">
        {{#each credential in user.credentials}}
          {{#if credential}}
          <li class="credential">
            <div class="login-provider-icon">
              <span class="provider-icon {{credential.serviceName}}">{{credential.serviceName}}</span>
            </div>
            <div class="credential-intrinsic-name">{{ credential.intrinsicName }}</div>
          </li>
          {{else}}
          <li class="credential">
            <div class="login-provider-icon">
              <span class="provider-icon">{{_ (con txt "unknownIdentity")}}</span>
            </div>
            <div class="credential-intrinsic-name">{{_ (con txt "unknownIdentifier")}}</div>
          </li>
          {{/if}}
        {{/each}}
      </ul>
    </div>
    <div class="created" role="gridcell">
      {{ dateString user.account.createdAt }}
    </div>
    <div class="last-active" role="gridcell">
      {{ dateString user.account.lastActive }}
    </div>
    {{#with userId=user.account._id }}
    <div class="actions" role="gridcell">{{#linkTo route="newAdminUserDetails" data=(wrapUserId userId) class="manage-user-button"}}{{_ "admin.userAccounts.newAdminUserTableRow.manageButton"}}{{/linkTo}}</div>
    {{/with}}
  </div>
{{/let}}
</template>

<template name="newAdminUserTable">
{{#let txt="admin.userAccounts.newAdminUserTable"}}
{{!-- Expects:
  showInvite: Boolean.  If true, shows the "invite" row.
       ready: Boolean.  If true, display all the users.  If false, display a loading message.
       users: Array of Objects representing users, see shape below.
--}}
  <div class="admin-user-table" role="grid">
    <div role="rowgroup">
      <div class="header-row" role="row">
        {{#with sortOrder=sortOrder}}
        <div class="account-role" role="columnheader"></div>
        <div class="profile-name" role="columnheader">{{_ (con txt "header.name")}}</div>
        <div class="credentials" role="columnheader">{{_ (con txt "header.credentials")}}</div>
        <div class="created" role="columnheader">
          {{_ (con txt "header.created")}}
          {{#if equal sortOrder.key "createdAt"}}
            {{#if equal sortOrder.order "ascending"}}
              ▾
            {{else}}
              ▴
            {{/if}}
          {{/if}}
        </div>
        <div class="last-active" role="columnheader">
          {{_ (con txt "header.lastActive")}}
          {{#if equal sortOrder.key "lastActive"}}
            {{#if equal sortOrder.order "ascending"}}
              ▾
            {{else}}
              ▴
            {{/if}}
          {{/if}}
        </div>
        <div class="actions" role="columnheader">{{_ (con txt "header.actions")}}</div>
        {{/with}}
      </div>
    </div>

    <div role="rowgroup">
    {{#if showInvite}}
      <div class="invite-row" role="row">
        <div class="account-role" role="gridcell"><span class="plus-icon"></span></div>
        <div class="invite-link" role="gridcell" colspan="4">{{#linkTo route="newAdminUserInvite"}}{{_ "admin.userAccounts.newAdminUserTable.inviteLink"}}{{/linkTo}}</div>
      </div>
    {{/if}}

    {{!-- for each account, look up the credentials --}}
    {{#if ready}}
      {{#each user in sortUsers users }}
        {{> newAdminUserTableRow user=user}}
      {{else}}
        <div class="no-match-row" role="row">
          <div class="no-matches" role="gridcell" colspan=5>
            {{_ (con txt "notFound")}}
          </div>
        </div>
      {{/each}}
    {{else}}
      <div class="loading-row" role="row">
        <div role="gridcell" colspan="5">{{_ (con txt "processing")}}</div>
      </div>
    {{/if}}
    </div>
  </div>
{{/let}}
</template>


<template name="newAdminUsers">
{{#let txt="admin.userAccounts.newAdminUsers"}}
  <h1>
    <ul class="admin-breadcrumbs">
      <li>{{#linkTo route="newAdminRoot"}}{{_ "admin.title"}}{{/linkTo}}</li>
      <li>{{_ "admin.users.name"}}</li>
    </ul>
  </h1>

  {{#with users=allUsers ready=userSubReady}}
  <div class="admin-user-filters">
    <span class="search-icon"></span>
    <input class="search-bar" name="search-bar" placeholder="{{_ (con txt "search.placeholder")}}" />
    <div class="filter-user-classes">
      <div class="show-label">
        {{_ (con txt "filter.explanation")}}
      </div>
      <div class="filter-boxes">
        <label>
          <input type="checkbox" name="show-admins" checked="{{showAdmins}}">
          <span class="user-class-admin">{{_ (con txt "filter.admin")}}</span> {{#if ready}}({{adminCount users}}){{/if}}
        </label>
        <label>
          <input type="checkbox" name="show-users" checked="{{showUsers}}">
          <span class="user-class-user">{{_ (con txt "filter.user")}}</span> {{#if ready}}({{userCount users}}){{/if}}
        </label>
        <label>
          <input type="checkbox" name="show-visitors" checked="{{showVisitors}}">
          <span class="user-class-visitor">{{_ (con txt "filter.visitor")}}</span> {{#if ready}}({{visitorCount users}}){{/if}}
        </label>
      </div>
    </div>
  </div>

  {{> newAdminUserTable showInvite=isNotSearching users=(filterUsers users) ready=ready }}

  {{/with}}
{{/let}}
</template>
